import os


def visualize_graph(graph):
    """仅输出 Mermaid 文本到 data/graph.mmd；设置 DISABLE_GRAPH_VIZ=1 时跳过。"""
    try:
        mermaid_txt = graph.get_graph().draw_mermaid()
        out_dir = os.path.join(os.getcwd(), "data")
        os.makedirs(out_dir, exist_ok=True)
        out_path = os.path.join(out_dir, "graph.mmd")
        with open(out_path, "w", encoding="utf-8") as f:
            f.write(mermaid_txt)
    except Exception:
        # 静默失败，不影响主流程
        pass

